package com.example.tool.R;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回结果统一格式
 *
 * @author zhanglong
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    /**
     * 信息
     */
    private String msg;

    /**
     * 数据
     */
    private Object data;

    /**
     * 状态码
     */
    private Integer code;

    public R(Object data) {
        this.data = data;
    }


    public static R success(String msg, Object data, Integer code){
        return new R(msg, data, 200);
    }

    public static R success(String msg) {
        return new R(msg, null, 200);
    }

    public static R success(Object data) {
        return new R("OK", data, 200);
    }

    public static R success(String msg, Object data ) {
        return new R(msg, data, 200);
    }

    public static R fail(String msg) {
        return new R(msg, null, 1500);
    }

    public static R fail(Object data) {
        return new R("OK", data, 1500);
    }

    public static R fail(Object data, String msg) {
        return new R(msg, data,1500);
    }

    public static R fail(String msg, Integer code) {
        return new R(msg, null, code);
    }
}
